<template>
  <div class="transaction-service-list bg-c-fff right-height mb70">
    <p class="bread rel">
      <a href="" class="font-s-16">业务管理部-法律服务通知</a>
    </p>
    <div class="content">
      <choose-type typename="操作状态" valuename="stateType" :itemlist="statelist" :active="stateActive" @typechanged="onOptionChanged"></choose-type>
      <choose-type typename="监控类型" valuename="type" :itemlist="typelist" :active="typeActive" @typechanged="onOptionChanged"></choose-type>
      <table width="100%" class="auto">
        <tr>
          <th>发送时间</th>
          <th>通知类型</th>
          <th>读取状态</th>
          <th>通知标题</th>
          <th>订单编号</th>
          <th>操作</th>
        </tr>
        <tr v-for="item in list">
          <td>{{item.createTime}}</td>
          <td>{{item.msgKind | msgKindFilter}}</td>
          <td>{{item.readType | readTypeFilter}}</td>
          <td>{{item.msgTittle}}</td>
          <td>{{item.orderNum}}</td>
          <td>
            <button class="blue-button small-btn-css" @click="onDetailsClick(item.orderNum,item.orderStatus)">订单详情</button>
            <button class="blue-button small-btn-css" @click="onConClick(item,item.msgKind)">通知内容</button>
          </td>
        </tr>
      </table>
      <div class="fix foot-box">
        <pagination :index="pageIndex" :total="pageTotal" v-show="this.list!=0" @pagechange="onPageChange"></pagination>
      </div>
    </div>
    <vodal :show="normalShow" animation="zoom" :width="420" :height="404" @hide="normalShow = false">
      <div class="vodal-main">
        <h4>{{title}}</h4>
        <div class="con">
          <ul>
            <li>发送时间：{{time}}</li>
            <li>订单编号：{{num}}</li>
            <li>用户信息：{{name}}</li>
            <li>律师信息：{{lawyerName}}</li>
            <li><span class="dib">消息内容：</span>
              <div class="dib vt">{{msgCon}}</div>
            </li>
          </ul>
        </div>
        <div class="tc auto vodal-btn-box">
          <button class="blue-button" @click="normalShow = false">确认</button>
          <button class="white-button" @click="normalShow = false">取消</button>
        </div>
      </div>
    </vodal>
    <vodal :show="abnormalShow" animation="zoom" :width="420" :height="404" @hide="abnormalShow = false">
      <div class="vodal-main">
        <h4>{{title}}</h4>
        <div class="con">
          <ul>
            <li>发送时间：{{time}}</li>
            <li>订单编号：{{num}}</li>
            <li>管理角色：{{name}}</li>
            <li><span class="dib">消息内容：</span>
              <div class="dib vt">{{msgCon}}</div>
            </li>
          </ul>
        </div>
        <div class="tc auto vodal-btn-box">
          <button class="blue-button" @click="abnormalShow = false">确认</button>
          <button class="white-button" @click="abnormalShow = false">取消</button>
        </div>
      </div>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import Pagination from '../components/Pagination'
import ChooseType from '../components/ChooseType'
export default {
  components: {
    Pagination,
    ChooseType
  },
  data() {
    return {
      pageIndex: 1,
      pageTotal: 0,
      normalShow: false,
      abnormalShow: false,
      stateActive: '',
      statelist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '正常通知'
      }, {
        value: '4',
        text: '异常通知'
      }],
      typeActive: '',
      typelist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '已读'
      }, {
        value: '0',
        text: '未读'
      }],
      list: [],
      title: '',
      time: '',
      num: '',
      name: '',
      lawyerName: '',
      msgCon: ''
    }
  },
  mounted() {
    this.onPageChange(1)
  },
  methods: {
    onOptionChanged(type, value) {
      if (type === 'stateType') {
        this.stateActive = value
      }
      if (type === 'type') {
        this.typeActive = value
      }
      this.getData(1)
    },
    onPageChange(n) {
      this.getData(n)
    },
    getData(n) {
      this.$http.get('/message/query/sysMsg', {
        params: {
          sendType: 1,
          readType: this.typeActive,
          msgKind: this.stateActive,
          page: n,
          rows: 10
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.pageIndex = n
          this.pageTotal = Math.ceil(data.data.total / 10)
          this.list = data.data.rows
        } else {
          console.log(data.data.msg)
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    onConClick(item, msgKind) {
      if (msgKind === 1) {
        this.normalShow = true
        this.lawyerName = item.lawyerInfo
      } else if (msgKind === 4) {
        this.abnormalShow = true
      }
      if (item.readType === 0) {
        this.$http.post('/message/modify/read/type', {
          messageId: item.id
        }).then(data => {
          if (data.data.httpCode === 200) {
          } else {
            console.log(data.data.msg)
          }
        }).catch(err => {
          console.log(err)
          this.$toasted.show('网络错误')
        })
      }
      item.readType = 1
      this.title = item.msgTittle
      this.time = item.createTime
      this.num = item.id
      this.name = item.userInfo
      this.msgCon = item.msgContent
    },
    onDetailsClick(id, status) {
      if (status === 1) {
        this.$router.push('/cm-law-notice?type=lawNotice&id=' + id)
      }
      if (status === 2) {
        this.$router.push('/cm-law-drawing?type=lawNotice&id=' + id)
      }
      if (status === 3) {
        this.$router.push('/cm-law-monitor?type=lawNotice&id=' + id)
      }
      if (status === 4) {
        this.$router.push('/cm-law-complete?type=lawNotice&id=' + id)
      }
      if (status === 5) {
        this.$router.push('/cm-law-complete?type=lawNotice&id=' + id)
      }
    }
  },
  filters: {
    msgKindFilter(v) {
      if (v === 1) {
        return '正常通知'
      } else if (v === 4) {
        return '异常通知'
      }
    },
    readTypeFilter(v) {
      if (v === 0) {
        return '未读'
      } else if (v === 1) {
        return '已读'
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.right-height {
  min-height: 700px;
}

.bread {
  padding-left: 20px;
  border-bottom: 1px solid #ddd;
}

.bread a {
  line-height: 45px;
}

.foot-box {
  padding: 35px 0px 0px 0px;
}

.pagination {
  width: 400px!important;
  margin: 0 auto!important;
}

.content {
  margin-top: 30px;
  padding: 0 30px;
}

table {
  margin-top: 20px;
}

.vodal-main .con {
  padding: 0px 20px 10px 20px;
  border: 1px solid #ddd;
}

.vodal-main div.dib {
  width: 260px;
  height: 105px;
}

</style>
